package cn.edu.nju.ws.sview.rdf.canonicalization.comparator;

import java.util.ArrayList;
import java.util.Comparator;

import cn.edu.nju.ws.sview.rdf.canonicalization.labeled.LabeledResource;

/**
 * @author Gong Cheng
 * 
 */
public class StatementComparator implements
		Comparator<ArrayList<LabeledResource>> {
	private Comparator<LabeledResource> labeledResourceComparator = null;

	private StatementComparator() {
		/* Nothing */
	}

	public StatementComparator(
			Comparator<LabeledResource> labeledResourceComparator) {
		this.labeledResourceComparator = labeledResourceComparator;
	}

	public int compare(ArrayList<LabeledResource> s1,
			ArrayList<LabeledResource> s2) {
		for (int i = 0; i < 3; i++) {
			LabeledResource r1 = s1.get(i);
			LabeledResource r2 = s2.get(i);

			int result = this.labeledResourceComparator.compare(r1, r2);
			if (result != 0) {
				return result;
			}
		}

		return 0;
	}

	public void close() {
		this.labeledResourceComparator = null;
	}
}